<?php

	eb_include_class("EbTableSQLModel");

	class FilterModel extends EbTableSQLModel
	{
		public function __construct()
		{
			parent::init('eb_filter','Core/FilterVO','fi_id');
		}
		
		public function getColumns()
		{
			return array(
				new EbTableColumn("fi_id","int",true,EB_PRIMARY_KEY,true),
				new EbTableColumn("module","varchar(64)"),
				new EbTableColumn("file","varchar(64)"),
				new EbTableColumn("data","varchar(256)",false)
			);
		}
		
		public function create()
		{
			if (parent::create())
			{
				$this->insert(array("module" => "Core","file" => "EbCore"));
			}
		}
		
		public function selectPreparedFilters()
		{
			$list = parent::select();
			$listInstances = array();
						
			foreach ($list AS $item)
			{
				try
				{
					$buffer = eb_module_file_new_instance($item->module,$item->file,MODULE_FILE_FILTER);
				
					$buffer->data = eb_parse_parameters_string($item->data);
				
					$listInstances []= $buffer;
				}
				catch (Exception $ex)
				{
					echo $ex;
				}
			}
						
			return $listInstances;
		}
	}